package com.pb.wkflow.core.camunda.bpmn.instanceImpl;

import com.pb.wkflow.core.camunda.bpmn.instance.RuleLogicParam;
import com.pb.wkflow.core.camunda.bpmn.instance.UserParticipant;
import lombok.extern.slf4j.Slf4j;
import org.camunda.bpm.model.bpmn.impl.instance.BpmnModelElementInstanceImpl;
import org.camunda.bpm.model.xml.ModelBuilder;
import org.camunda.bpm.model.xml.impl.instance.ModelTypeInstanceContext;
import org.camunda.bpm.model.xml.type.ModelElementTypeBuilder;
import org.camunda.bpm.model.xml.type.attribute.Attribute;

import static org.camunda.bpm.model.bpmn.impl.BpmnModelConstants.CAMUNDA_NS;

/**
 * @author 苗益辉
 * @date 2022/5/17 13:49
 */
@Slf4j
public class RuleLogicParamImpl extends BpmnModelElementInstanceImpl implements RuleLogicParam {

    /** 参数键 */
    protected static Attribute<String> paramAttribute;
    /** 名称 */
    protected static Attribute<String> nameAttribute;
    /** 参数类型 */
    protected static Attribute<String> typeAttribute;
    /** 参数值 */
    protected static Attribute<String> valueAttribute;

    public RuleLogicParamImpl(ModelTypeInstanceContext instanceContext) {
        super(instanceContext);
    }


    public static void registerType(ModelBuilder modelBuilder) {
        log.info("注册人工节点参与逻辑 RuleLogicParam");
        ModelElementTypeBuilder typeBuilder = modelBuilder.defineType(RuleLogicParam.class, "ruleLogicParam")
                .namespaceUri(CAMUNDA_NS)
                .instanceProvider(new ModelElementTypeBuilder.ModelTypeInstanceProvider<RuleLogicParam>() {
                    @Override
                    public RuleLogicParam newInstance(ModelTypeInstanceContext instanceContext) {
                        return new RuleLogicParamImpl(instanceContext);
                    }
                });

        paramAttribute = typeBuilder.stringAttribute("param").namespace(CAMUNDA_NS).build();
        nameAttribute = typeBuilder.stringAttribute("name").namespace(CAMUNDA_NS).build();
        typeAttribute = typeBuilder.stringAttribute("type").namespace(CAMUNDA_NS).build();
        valueAttribute = typeBuilder.stringAttribute("value").namespace(CAMUNDA_NS).build();
        typeBuilder.build();
    }

    @Override
    public String getParam() {
        return paramAttribute.getValue(this);
    }

    @Override
    public void setParam(String param) {
        paramAttribute.setValue(this,param);
    }

    @Override
    public String getName() {
        return nameAttribute.getValue(this);
    }

    @Override
    public void setName(String name) {
        nameAttribute.setValue(this,name);
    }

    @Override
    public String getType() {
        return typeAttribute.getValue(this);
    }

    @Override
    public void setType(String type) {
        typeAttribute.setValue(this,type);
    }

    @Override
    public String getValue() {
        return valueAttribute.getValue(this);
    }

    @Override
    public void setValue(String value) {
        valueAttribute.setValue(this,value);
    }
}
